package com.service;

import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dao.TestTableDao;
import com.entity.TestTable;
import com.util.TimeUtil;

@Service
public class TestServiceImpl implements ITestService {

	@Resource
	private TestTableDao testTableDao;

	@Override
	public void save() {
		TestTable testTable = new TestTable();
		InetAddress addr;
		try {
			addr = InetAddress.getLocalHost();
			String ip = addr.getHostAddress().toString();
			String address = addr.getHostName().toString();
			System.out.printf("IP:[%s] , hostName:[%s]", ip, address);

			testTable.setHostName(address);
			testTable.setIp(ip);
			testTable.setMessage("");
			testTable.setEvtTimestamp(TimeUtil.getCurrentTimestamp());

			testTableDao.saveData(testTable);
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}

	}

}
